<template>
	<web-view :webview-styles="webviewStyles" :src="webviewUrl"></web-view>
</template>

<script>
export default {
	data() {
		return {
			openid: '',
			webviewUrl: '',
			webviewStyles: {
				progress: {
					color: '#2b85e4'
				}
			}
		};
	},
	async onLoad(options) {
		if (!this.vuex_openid) {
			// this.openid = await this.getWxOpenId()
			this.openid = null
		} else {
			this.openid = this.vuex_openid
		}
		let pages = getCurrentPages();
		let route = pages[pages.length - 1].route;
		console.log(route)
		let formKey = options.formKey
		// 扫码进入
		if (options.scene) {
			formKey = options.scene
		}
		this.webviewUrl = this.$u.api.getWebBaseUrl() +
			`/s/${formKey}?openId=${this.openid}&token=${this.vuex_token}&redirect=/${route}&params=${JSON.stringify(options)}`
	},
	methods: {
		wxLogin() {
			let that = this
			return new Promise(function (reslove, reject) {
				uni.login({
					"provider": "weixin",
					success: function (event) {
						that.$u.api.getOpenid({
							code: event.code
						}).then(res => {
							that.openid = res
							reslove(res);
						})
					}
				})
			})
		},
		async getWxOpenId() {
			const res = await this.wxLogin()
			return res
		}
	}
}
</script>

<style lang="scss">

</style>
